package com.virus.coronavirus.controller;

import com.virus.coronavirus.error.SystemException;
import com.virus.coronavirus.model.Action;
import com.virus.coronavirus.model.vo.ActionVO;
import com.virus.coronavirus.model.vo.CompareVO;
import com.virus.coronavirus.model.vo.MeetVO;
import com.virus.coronavirus.response.ControllerEndpoint;
import com.virus.coronavirus.response.ResponseBean;
import com.virus.coronavirus.service.ActionService;
import com.virus.coronavirus.service.TrackService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author: Bbeginner
 * @Date: 2021/3/21 14:29
 * @Version 1.0
 **/
@RestController
@RequestMapping("/virus/meet")
@Validated
@Api(tags = "疫情防控模块-算法相关接口")
public class ActionController {
    @Autowired
    private TrackService trackService;

    @Autowired
    private ActionService actionService;

    @ApiOperation(value = "查找用户附近的风险区域", notes = "指定距离,获取附近的风险区域")
    @RequiresPermissions({"track:find"})
    @GetMapping("/areadistance")
    public ResponseBean areadistance(Long id1, Double dis) throws Exception {
        List<CompareVO> areadistance = trackService.areadistance(id1, dis);
        return ResponseBean.success(areadistance);
    }

    @ApiOperation(value = "查找相交轨迹", notes = "指定时间,获取相交的轨迹")
    @RequiresPermissions({"track:find"})
    @GetMapping("/useraction")
    public ResponseBean useraction(Long id1, Long id2, Double dis, long time) throws Exception {
        List<MeetVO> useraction = trackService.useraction(id1, id2, dis, time);
        return ResponseBean.success(useraction);
    }

    @ApiOperation(value = "判定是否相遇", notes = "指定时间,进行判定")
    @RequiresPermissions({"track:find"})
    @GetMapping("/userconflict")
    public ResponseBean userconflict(Long id1, Long id2, Double dis, long time) throws Exception {
        Boolean useraction = trackService.userconflict(id1, id2, dis, time);
        return ResponseBean.success(useraction);
    }

    /***************************************************************************************************/

    @ControllerEndpoint(exceptionMessage = "删除数据失败", operation = "删除数据")
    @RequiresPermissions({"user:delete"})
    @ApiOperation(value = "删除数据单条", notes = "删除信息，根据ID")
    @DeleteMapping("/delete/{id}")
    public ResponseBean delete(@PathVariable Long id) throws SystemException {
        actionService.deleteById(id);
        return ResponseBean.success();
    }

    @ControllerEndpoint(exceptionMessage = "删除数据失败", operation = "删除数据")
    @RequiresPermissions({"user:delete"})
    @ApiOperation(value = "删除数据批量通过用户1的id", notes = "删除信息，根据ID")
    @DeleteMapping("/deleteuser/{id}")
    public ResponseBean deleteByUserid(@PathVariable Long id) throws SystemException {
        actionService.deleteByUserid1(id);
        return ResponseBean.success();
    }

    @ControllerEndpoint(exceptionMessage = "删除数据失败", operation = "删除数据")
    @RequiresPermissions({"user:delete"})
    @ApiOperation(value = "删除所有数据", notes = "删除信息")
    @DeleteMapping("/deleteall")
    public ResponseBean deleteAll() throws SystemException {
        actionService.deleteAll();
        return ResponseBean.success();
    }

    @ApiOperation(value = "通过用户1的id查询数据", notes = "查询信息,根据用户1id")
    @GetMapping("/userid1/{id}")
    public ResponseBean findByUserid1(@PathVariable Long id) throws SystemException {
        List<Action> userid1 = actionService.findByUserid1(id);
        return ResponseBean.success(userid1);
    }

    @ApiOperation(value = "通过用户2的id查询数据", notes = "查询信息,根据用户2id")
    @GetMapping("/userid2/{id}")
    public ResponseBean findByUserid2(@PathVariable Long id) throws SystemException {
        List<Action> userid1 = actionService.findByUserid2(id);
        return ResponseBean.success(userid1);
    }

    @ApiOperation(value = "通过状态查询用户", notes = "查询所有相同状态的用户")
    @GetMapping("/usermeet{meet}")
    public ResponseBean findUserByStatus(@PathVariable String meet){
        List<Action> bymeet = actionService.findBymeet(meet);
        return ResponseBean.success(bymeet);
    }

    @ControllerEndpoint(exceptionMessage = "添加数据失败", operation = "添加数据")
    @ApiOperation(value = "添加数据", notes = "添加信息")
    @RequiresPermissions({"meeet:add"})
    @PostMapping("/add")
    public ResponseBean add(@RequestBody @Validated ActionVO actionVO) throws SystemException {
        actionService.add(actionVO);
        return ResponseBean.success();
    }


}
